/*
 * comlan
 */

package com.promfy.settings.deviceinfo;

import java.lang.reflect.Method;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;

import com.promfy.util.L;

public class DeviceInfo {
	private static final String TAG = "DeviceInfo";
    
	public static final String DEVICE_INFO_VERSION = "firmware_version";
	public static final String DEVICE_INFO_MODEL = "device_model";
	public static final String DEVICE_INFO_NAME = "device_name";
	public static final String DEVICE_INFO_VENDOR = "device_vendor";
	public static final String DEVICE_INFO_SN = "device_sn";
	public static final String DEVICE_INFO_WEB = "device_web";
	public static final String DEVICE_INFO_EMAIL = "device_email";
//	public static final String DEVICE_INFO_BUILD_NUMBER = "build_number";
//	public static final String DEVICE_INFO_KERNEL_VERSION = "kernel_version";
//	public static final String DEVICE_INFO_BASEBAND_VERSION = "baseband_version";
    
    
	private static Method getMethod;

	public static Method initGetMethod(){
		Method get_Method = null;
		try {
			Class hideClass = Class.forName("android.os.SystemProperties");
			Object invokeOperation = hideClass.newInstance();
			get_Method = hideClass.getMethod("get", String.class);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return get_Method;
	}
	
	public static String getDeviceInfo(String param){
		if(getMethod == null) {
			getMethod = initGetMethod();
		}
		String info = null;
		try {
			info = (String)getMethod.invoke(null, new Object[] { new String(param) });
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		L.d(TAG, info.toString());   
		return info;
	}
	
	public static String getAppInfo(Context context,String packageName){
		String version = "";
		PackageManager pm = context.getPackageManager();
		PackageInfo pi;
		try {
			pi = pm.getPackageInfo(packageName, 0);
			version = pi.versionName + "_" + pi.versionCode;
		} catch (NameNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return version;
	}
}
